import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:top_foundation/utils/theme/button.dart';
import 'package:whale/helper/component/record_add_item.dart';
import 'package:whale/helper/utils/ifly/ifly_util.dart';
import 'package:whale/helper/utils/ifly/sound.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class AudioPage extends GetView<AudioController> {
  const AudioPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return ListView(
      children: [
        IButton.text(
            onPressed: () {
              IFlyUtil().ifly_audio().then((value) {
                // if (result != null && value.dataJson.isNotEmpty) {
                //   result!(AudioListModel.fromJson(value.dataJson));
                // }
              });
            },
            text: '123'),
        RecordAddItemWidget(
          '录音测试',
          editText: state.text,
          onChanged: (text) {
            state.text = text;
          },
          audioOnChanged: (p0) {},
        ),
        FilledButton(
            onPressed: () {
              SoundMan().play(
                  'http://khx.test.biaomengwang.com/static/upload/chat/audio/20240815/a59c541288d87c1e4983a1db178a587a.aac');
            },
            child: Text('播放在线录音')),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AudioController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("audio")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
